﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

public partial class EditYiGongBaoMing : System.Web.UI.PageEx
{
    private DataSet ds = null;
    public static string strId = "0";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string strResult = string.Empty;
            if (!DalEx.DbUserDalEx.CheckUserLogin(UserType, UserId, ref strResult))
            {
                MessageBox(strResult, "UserLogin.aspx");
                return;
            }
            else
            {
                string strLink = "<li><a href=\"{0}\" class=\"{2}\">{1}</a></li>";
                StringBuilder sbMenuLinks = new StringBuilder();
                if (UserType == 1 && UserId > 0)
                {
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "MemberCenter.aspx", "会员中心", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "UserInfos.aspx", "我的资料", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "ModifyPwd.aspx", "修改密码", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "MyBaoMing.aspx", "我的报名表", "on" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "MyYiGongBaoMing.aspx", "义工报名表", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "MyHomeEventBaoMing.aspx", "家园活动报名表", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "Logout.aspx", "退出系统", "" }));
                }
                else
                {
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "会员中心", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "我的资料", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "修改密码", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "我的报名表", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "义工报名表", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "家园活动报名表", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "退出系统", "" }));
                }
                litMenuLinks.Text = sbMenuLinks.ToString();

                DataBinds();
            }
        }
    }
    private void DataBinds()
    {
        if (!string.IsNullOrEmpty(Request.QueryString["Id"]))
        {
            strId = Request.QueryString["Id"].ToString();
        }
        int iUserId = 0;
        int.TryParse(strId, out iUserId);

        Model.BaoMing2 M_BaoMing = Dal.BaoMing2Dal.Select(iUserId);
        if (M_BaoMing != null)
        {
            hfSelectId.Value = M_BaoMing.Id.ToString();
            txtBabyName.Text = M_BaoMing.BabyName;
            txtParentName.Text = M_BaoMing.ParentName;
            ddlParentEducation.SelectedIndex = ddlParentEducation.Items.IndexOf(ddlParentEducation.Items.FindByValue(M_BaoMing.ParentEducation));
            txtMobile.Text = M_BaoMing.Mobile;
            txtWorkUnit.Text = M_BaoMing.WorkUnit;
            txtParentSkill.Text = M_BaoMing.ParentSkill;
            txtResources.Text = M_BaoMing.Resources;
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string strOrderSN = WebBase.Comm.GetOrderNo("ZC");
        string strBabyName = SqlHelper.String(txtBabyName.Text);
        string strParentName = SqlHelper.String(txtParentName.Text);
        string strParentEducation = SqlHelper.String(ddlParentEducation.SelectedValue);
        string strMobile = SqlHelper.String(txtMobile.Text);
        string strWorkUnit = SqlHelper.String(txtWorkUnit.Text);
        string strParentSkill = SqlHelper.String(txtParentSkill.Text);
        string strResources = SqlHelper.String(txtResources.Text);
        if (strBabyName.Length > 50)
        {
            MessageBox("幼儿姓名不能超过50个字！");
            return;
        }
        if (strParentName.Length > 100)
        {
            MessageBox("幼儿姓名不能超过100个字！");
            return;
        }
        if (strParentEducation == "")
        {
            MessageBox("请选择家长学历！");
            return;
        }
        if (strMobile.Length > 50)
        {
            MessageBox("联系电话不能超过50个字！");
            return;
        }
        if (strWorkUnit.Length > 200)
        {
            MessageBox("工作单位不能超过200个字！");
            return;
        }
        if (strParentSkill.Length > 250)
        {
            MessageBox("家长特长不能超过250个字！");
            return;
        }
        if (strResources.Length > 500)
        {
            MessageBox("可提供的资源不能超过500个字！");
            return;
        }
        int iUserId = 0;
        int.TryParse(hfSelectId.Value, out iUserId);
        Model.BaoMing2 M_BaoMing2 = Dal.BaoMing2Dal.Select(iUserId);
        M_BaoMing2.BabyName = strBabyName;
        M_BaoMing2.ParentName = strParentName;
        M_BaoMing2.ParentEducation = strParentEducation;
        M_BaoMing2.Mobile = strMobile;
        M_BaoMing2.WorkUnit = strWorkUnit;
        M_BaoMing2.ParentSkill = strParentSkill;
        M_BaoMing2.Resources = strResources;
        if (Dal.BaoMing2Dal.Update(M_BaoMing2) > 0)
        {
            MessageBox("修改成功！！！", "MyYiGongBaoMing.aspx");
        }
        else
        {
            MessageBox("未能完成修改！");
        }
    }
}
